<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

namespace J\UI\Engine\Thinkphp;

use J\UI\Engine\Thinkphp;


/**
 * ThinkPHP标签库TagLib解析基类
 */
class TagLib
{

    /**
     * 标签库标签列表
     * @var []
     */
    protected $tags = array();
    /**
     * 当前模板引擎对象
     * @var Thinkphp
     */
    protected $tpl;

    protected $comparison = array(' nheq ' => ' !== ', ' heq ' => ' === ', ' neq ' => ' != ', ' eq ' => ' == ', ' egt ' => ' >= ', ' gt ' => ' > ', ' elt ' => ' <= ', ' lt ' => ' < ');

    /**
     * 架构函数
     * @param Thinkphp $t
     */
    public function __construct(Thinkphp $t)
    {
        $this->tpl = $t;
    }

    // 获取标签定义

    /**
     * 获取标签库对象
     * @param string $tagLib
     * @param Thinkphp $engine
     * @return TagLib | boolean
     */
    public static function getTagLib($tagLib, $engine)
    {
        $class = __NAMESPACE__ . '\\TagLib\\' . ucfirst($tagLib);
        if (class_exists($class)) {
            return new $class($engine);
        }
        return false;
    }

    /**
     * @return array
     */
    public function getTags()
    {
        return $this->tags;
    }

    public function parseXmlTag($tag, $attributes, $content)
    {
        $parse = '_' . $tag;
        $content = trim($content);
        return $this->$parse($attributes, $content);
    }
}